package com.consumer.controller;

import com.consumer.bean.Order;
import com.consumer.util.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Description:
 *
 * @author weiruibai.vendor
 * Date: 2022/9/14 22:47
 */
@RestController
@Slf4j
public class ConsumerController {

    private static final String ORDER_SERVER = "http://ORDER-SERVER/order";

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/order")
    public CommonResult order(@RequestBody Order order) {
        return restTemplate.postForObject(ORDER_SERVER + "/order", order, CommonResult.class);
    }

    @GetMapping("/get")
    public CommonResult get(@RequestParam("id") Integer id) {
        return restTemplate.getForObject(ORDER_SERVER + "/get/?id=" + id, CommonResult.class);
    }

    @GetMapping("/getList")
    public CommonResult getList() {
        return restTemplate.getForObject(ORDER_SERVER + "/getList/", CommonResult.class);
    }

    @GetMapping("/getPort")
    public Object getEnvironment() {
        return restTemplate.getForObject(ORDER_SERVER + "/getPort", String.class);
    }

}
